﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AKMII.DMRA.Business.Management;
using AKMII.DMRA.Business.Rule;
using AKMII.DMRA.Common;

namespace AKMII.DMRA.Web.MDPages
{
    public partial class AddRatios : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int agentId=int.Parse(Request.QueryString[0]);
                this.Button1.Attributes.Add("onclick", "return checkValidate()");
                DataBind(0.45, 0.3,agentId);
                this.txtAAK.Attributes.Add("onkeyup", "validateNumber(this.value)");
                this.txtAAM.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtAAvg.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtAcon.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtAPre.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtASale.Attributes.Add("onkeyup", "validateNumber(this.value)"); 

                this.txtLAK0.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtLAM.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtLcon.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtLPre0.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtLSale.Attributes.Add("onkeyup", "validateNumber(this.value)"); 

                this.txtNAK0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtNAM0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtNcon.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtNPre.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtNSale.Attributes.Add("onkeyup", "validateNumber(this.value)");  

                this.txtBAK.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtBAM.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtBcon.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtBPre.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtBSale.Attributes.Add("onkeyup", "validateNumber(this.value)"); 

                this.txtRAK0.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtRAM.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtRcon.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtRPre.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtRSale.Attributes.Add("onkeyup", "validateNumber(this.value)"); 

                this.txtTMAK0.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtTMAM0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtTMcon.Attributes.Add("onkeyup", "validateNumber(this.value)"); 
                this.txtTMPre.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtTMSale.Attributes.Add("onkeyup", "validateNumber(this.value)"); 

                this.txtFAK0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtFAM0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtFPre.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtFRcon.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtFRSale.Attributes.Add("onkeyup", "validateNumber(this.value)"); 

                this.txtTSAK0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtTSAM0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtTScon0.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtTSPre.Attributes.Add("onkeyup", "validateNumber(this.value)");  
                this.txtTSSale.Attributes.Add("onkeyup", "validateNumber(this.value)");  
            }
        }

        private void DataBind(double classRate, double classRate2, int agentID)
        {
            AccountManager accountManager = new AccountManager();
            Assignment assignment = accountManager.GetAssignment(User.Identity.Name.ToString(), agentID);
            assignment.ClassRate = 0.45;
            assignment.ClassRate2 = 0.3;
            this.txtAAK.Text = Convert.ToString(assignment.ActiveAppointKept * 100) + "%";
            this.txtAAM.Text = Convert.ToString(assignment.ActiveAppointMade * 100) + "%";
            this.txtAAvg.Text = "$" + Convert.ToString(assignment.AAvgAPV);
            this.txtAcon.Text = Convert.ToString(assignment.ActiveContacts * 100) + "%";
            this.txtAPre.Text = Convert.ToString(assignment.ActivePresentation * 100) + "%";
            this.txtASale.Text = Convert.ToString(assignment.ActiveAppointSale * 100) + "%";

            this.txtLAK0.Text = Convert.ToString(assignment.LapsedAppointKept * 100) + "%";
            this.txtLAM.Text = Convert.ToString(assignment.LapsedAppointMade * 100) + "%";
            this.txtLcon.Text = Convert.ToString(assignment.LapsedContacts * 100) + "%";
            this.txtLPre0.Text = Convert.ToString(assignment.LapsedPresentation * 100) + "%";
            this.txtLSale.Text = Convert.ToString(assignment.LapsedAppointSale * 100) + "%";

            this.txtNAK0.Text = Convert.ToString(assignment.NeighborAppointKept * 100) + "%";
            this.txtNAM0.Text = Convert.ToString(assignment.NeighborAppointMade * 100) + "%";
            this.txtNcon.Text = Convert.ToString(assignment.NeighborContacts * 100) + "%";
            this.txtNPre.Text = Convert.ToString(assignment.NeighborPresentation * 100) + "%";
            this.txtNSale.Text = Convert.ToString(assignment.NeighborAppointSale * 100) + "%";

            this.txtBAK.Text = Convert.ToString(assignment.BusinessAppointKept * 100) + "%";
            this.txtBAM.Text = Convert.ToString(assignment.BusinessAppointMade * 100) + "%";
            this.txtBcon.Text = Convert.ToString(assignment.BusinessContacts * 100) + "%";
            this.txtBPre.Text = Convert.ToString(assignment.BusinessPresentation * 100) + "%";
            this.txtBSale.Text = Convert.ToString(assignment.BusinessAppointSale * 100) + "%";

            this.txtRAK0.Text = Convert.ToString(assignment.RefAppointKept * 100) + "%";
            this.txtRAM.Text = Convert.ToString(assignment.RefAppointMade * 100) + "%";
            this.txtRcon.Text = Convert.ToString(assignment.RefContacts * 100) + "%";
            this.txtRPre.Text = Convert.ToString(assignment.RefPresentation * 100) + "%";
            this.txtRSale.Text = Convert.ToString(assignment.RefAppointSale * 100) + "%";

            this.txtTMAK0.Text = Convert.ToString(assignment.TargetMarketAppointKept * 100) + "%";
            this.txtTMAM0.Text = Convert.ToString(assignment.TargetMarketAppointMade * 100) + "%";
            this.txtTMcon.Text = Convert.ToString(assignment.TargetMarketContacts * 100) + "%";
            this.txtTMPre.Text = Convert.ToString(assignment.TargetMarketPresentation * 100) + "%";
            this.txtTMSale.Text = Convert.ToString(assignment.TargetMarketAppointSale * 100) + "%";

            this.txtFAK0.Text = Convert.ToString(assignment.FieldAppointKept * 100) + "%";
            this.txtFAM0.Text = Convert.ToString(assignment.FieldAppointMade * 100) + "%";
            this.txtFPre.Text = Convert.ToString(assignment.FieldPresentation * 100) + "%";
            this.txtFRcon.Text = Convert.ToString(assignment.FieldContacts * 100) + "%";
            this.txtFRSale.Text = Convert.ToString(assignment.FieldAppointSale * 100) + "%";

            this.txtTSAK0.Text = Convert.ToString(assignment.TSystemAppointKept * 100) + "%";
            this.txtTSAM0.Text = Convert.ToString(assignment.TSystemAppointMade * 100) + "%";
            this.txtTScon0.Text = Convert.ToString(assignment.TSystemContacts * 100) + "%";
            this.txtTSPre.Text = Convert.ToString(assignment.TSystemPresentation * 100) + "%";
            this.txtTSSale.Text = Convert.ToString(assignment.TSystemAppointSale * 100) + "%";

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            Assignment assignment = new Assignment();
            assignment.ActiveAppointKept =double.Parse( this.txtAAK.Text.Replace('%',' '))/100.0;
            assignment.ActiveAppointMade = double.Parse( this.txtAAM.Text.Replace('%',' '))/100.0;
            assignment.ActiveContacts = double.Parse( this.txtAcon.Text.Replace('%',' '))/100.0;
            assignment.ActivePresentation = double.Parse( this.txtAPre.Text.Replace('%',' '))/100.0;
            assignment.ActiveAppointSale = double.Parse( this.txtASale.Text.Replace('%',' '))/100.0;

            assignment.LapsedAppointKept = double.Parse( this.txtLAK0.Text.Replace('%',' '))/100.0;
            assignment.LapsedAppointMade = double.Parse( this.txtLAM.Text.Replace('%',' '))/100.0;
            assignment.LapsedContacts = double.Parse( this.txtLcon.Text.Replace('%',' '))/100.0;
            assignment.LapsedPresentation = double.Parse( this.txtLPre0.Text.Replace('%',' '))/100.0;
            assignment.LapsedAppointSale = double.Parse( this.txtLSale.Text.Replace('%',' '))/100.0;

            assignment.NeighborAppointKept = double.Parse( this.txtNAK0.Text.Replace('%',' '))/100.0;
            assignment.NeighborAppointMade = double.Parse( this.txtNAM0.Text.Replace('%',' '))/100.0;
            assignment.NeighborContacts = double.Parse( this.txtNcon.Text.Replace('%',' '))/100.0;
            assignment.NeighborPresentation = double.Parse( this.txtNPre.Text.Replace('%',' '))/100.0;
            assignment.NeighborAppointSale = double.Parse( this.txtNSale.Text.Replace('%',' '))/100.0;

            assignment.BusinessAppointKept = double.Parse( this.txtBAK.Text.Replace('%',' '))/100.0;
            assignment.BusinessAppointMade = double.Parse( this.txtBAM.Text.Replace('%',' '))/100.0;
            assignment.BusinessContacts = double.Parse( this.txtBcon.Text.Replace('%',' '))/100.0;
            assignment.BusinessPresentation = double.Parse( this.txtBPre.Text.Replace('%',' '))/100.0;
            assignment.BusinessAppointSale = double.Parse( this.txtBSale.Text.Replace('%',' '))/100.0;

            assignment.RefAppointKept = double.Parse( this.txtRAK0.Text.Replace('%',' '))/100.0;
            assignment.RefAppointMade = double.Parse( this.txtRAM.Text.Replace('%',' '))/100.0;
            assignment.RefContacts = double.Parse( this.txtRcon.Text.Replace('%',' '))/100.0;
            assignment.RefPresentation = double.Parse( this.txtRPre.Text.Replace('%',' '))/100.0;
            assignment.RefAppointSale = double.Parse( this.txtRSale.Text.Replace('%',' '))/100.0;

            assignment.TargetMarketAppointKept = double.Parse( this.txtTMAK0.Text.Replace('%',' '))/100.0;
            assignment.TargetMarketAppointMade = double.Parse( this.txtTMAM0.Text.Replace('%',' '))/100.0;
            assignment.TargetMarketContacts = double.Parse( this.txtTMcon.Text.Replace('%',' '))/100.0;
            assignment.TargetMarketPresentation = double.Parse( this.txtTMPre.Text.Replace('%',' '))/100.0;
            assignment.TargetMarketAppointSale = double.Parse( this.txtTMSale.Text.Replace('%',' '))/100.0;

            assignment.FieldAppointKept = double.Parse( this.txtFAK0.Text.Replace('%',' '))/100.0;
            assignment.FieldAppointMade = double.Parse( this.txtFAM0.Text.Replace('%',' '))/100.0;
            assignment.FieldPresentation = double.Parse( this.txtFPre.Text.Replace('%',' '))/100.0;
            assignment.FieldContacts = double.Parse( this.txtFRcon.Text.Replace('%',' '))/100.0;
            assignment.FieldAppointSale = double.Parse( this.txtFRSale.Text.Replace('%',' '))/100.0;

            assignment.TSystemAppointKept = double.Parse( this.txtTSAK0.Text.Replace('%',' '))/100.0;
            assignment.TSystemAppointMade = double.Parse( this.txtTSAM0.Text.Replace('%',' '))/100.0;
            assignment.TSystemContacts = double.Parse( this.txtTScon0.Text.Replace('%',' '))/100.0;
            assignment.TSystemPresentation = double.Parse( this.txtTSPre.Text.Replace('%',' '))/100.0;
            assignment.TSystemAppointSale = double.Parse( this.txtTSSale.Text.Replace('%',' '))/100.0;
            assignment.AgentId = int.Parse(Request.QueryString[0]);
            AccountManager account = new AccountManager();
            account.UpdateAgentRatio(assignment);
            string closeScript = "<script language='javascript'> window.opener=null;window.open(\"\",\"_self\");window.close();</script>";
            Response.Write(closeScript);

         }

        protected void Button2_Click(object sender, EventArgs e)
        {
            int agentId = int.Parse(Request.QueryString[0]);
            AccountManager accountManager = new AccountManager();
            accountManager.SetDefaultAgentRatio(agentId);
            DataBind(0.45, 0.3, agentId);
           
        }

    }
}
